package com.yicong.ants.ui.video;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cchao.simplelib.core.Router;
import com.cchao.simplelib.core.UiHelper;
import com.cchao.simplelib.ui.activity.BaseStatefulActivity;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.bean.video.FocusBean;
import com.yicong.ants.databinding.ActivityFocusListBinding;
import com.yicong.ants.manager.UserManager;
import com.yicong.ants.ui.video.adapter.FocusListAdapter;
import com.yicong.ants.utils.StatusBarUtil;

/**
 * 关注列表
 */
public class FocusListActivity extends BaseStatefulActivity<ActivityFocusListBinding> implements View.OnClickListener {
    RecyclerView mRecycler;
    FocusListAdapter mAdapter;
    String mUid;

    @Override
    protected int getLayout() {
        return R.layout.activity_focus_list;
    }

    @Override
    protected void initEventAndData() {
        StatusBarUtil.setStatusImmerAndTextWhite(getWindow());
        mDataBind.topField.setPadding(UiHelper.dp2px(15), StatusBarUtil.getStatusBarHeight(mContext), UiHelper.dp2px(15), UiHelper.dp2px(15));
        mRecycler = mDataBind.recycler;
        mUid = getIntent().getStringExtra(Constants.Extra.Uid);

        if (mUid.equals(UserManager.getUserId())) {
            mDataBind.tvName.setText("我的关注");
        } else {
            mDataBind.tvName.setText(getIntent().getStringExtra(Constants.Extra.Name) + "的关注");
        }

        mDataBind.setClick(this);
        initAdapter();
        onLoadData();
    }

    @Override
    protected void onLoadData() {
        mAdapter.loadPageData(1);
    }

    private void initAdapter() {
        mRecycler = mDataBind.recycler;
        mRecycler.setBackgroundResource(R.color.black);
        mRecycler.setLayoutManager(new LinearLayoutManager(mContext));
        mAdapter = new FocusListAdapter(this, mDisposable, mUid);
        mAdapter.setOnItemClickListener((adapter1, view, position) -> {
            FocusBean focusBean = mAdapter.getItem(position);
            Router.turnTo(mContext, VideoProfileActivity.class)
                .checkLogin(true)
                .putExtra(Constants.Extra.Video_isFocus, "1".equals(focusBean.getIs_focus()))
                .putExtra(Constants.Extra.Uid, focusBean.getFocus_id())
                .start();

        });
        mAdapter.bindToRecyclerView(mRecycler);
        mRecycler.setAdapter(mAdapter);
        mAdapter.loadPageData(1);
    }

    @Override
    public void onClick(View v) {
        if (R.id.iv_back == v.getId()) {
            onBackPressed();
        }
    }
}